package com.cts.tmall.app.controller;

import com.cts.tmall.biz.service.LimitSaleService;
import com.cts.tmall.dal.entity.TmallLimitSale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/limitSale")
public class LimitSaleController {

    @Autowired
    private LimitSaleService limitSaleService;

    @GetMapping
    public Map<String, Object> queryLimitSale(
            @RequestParam(name = "createUserId", required = false) Long createUserId,
            @RequestParam(name = "eventName", required = false) String eventName,
            @RequestParam(name = "status", required = false) String status,
            @RequestParam(name = "discountType", required = false) String discountType,
            @RequestParam(name = "pageNumb", required = false, defaultValue = "1") Long pageNumb,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10") Long pageSize) {
        return limitSaleService.queryLimitSale(createUserId, eventName, status, discountType, pageNumb, pageSize);
    }

    @PostMapping
    public TmallLimitSale addLimitSale(@RequestBody TmallLimitSale limitSale) {
        return limitSaleService.addLimitSale(limitSale);
    }

    @PutMapping
    public TmallLimitSale updLimitSale(@RequestBody TmallLimitSale limitSale) {
        return limitSaleService.updLimitSale(limitSale);
    }
}
